#include "Gk.h"

#ifdef GK_DEVICE_DIRECTX9

namespace gk
{
	void ConstantBuffer::SetConstant(GpuProgramConstantHandle hConstant, TextureHandle hTexture)
	{
		CR_ASSERT(hConstant.IsValid() && hTexture.IsValid());
		m_internal.m_textures[hConstant->m_offset].v = hTexture->m_internal.m_pTexture;
	}

	void ConstantBuffer::SetConstant(GpuProgramConstantHandle hConstant, float v)
	{
		CR_ASSERT(hConstant.IsValid());
		m_internal.m_floats[hConstant->m_offset].v[0] = v;
		m_internal.m_floats[hConstant->m_offset].v[1] = v;
		m_internal.m_floats[hConstant->m_offset].v[2] = v;
		m_internal.m_floats[hConstant->m_offset].v[3] = v;
	}

	void ConstantBuffer::SetConstant(GpuProgramConstantHandle hConstant, float* v, cr::size_t num)
	{
		CR_ASSERT(hConstant.IsValid());
		memcpy(m_internal.m_floats[hConstant->m_offset].v, v, num*sizeof(float)*4);
	}

	void ConstantBuffer::SetConstant(GpuProgramConstantHandle hConstant, cr::Vec4fRef v)
	{
		SetConstant(hConstant, (float*)&v, 1);
	}
	
	void ConstantBuffer::SetConstant(GpuProgramConstantHandle hConstant, cr::Matrix4fRef v)
	{
		SetConstant(hConstant, (float*)&v, hConstant->m_size);
	}
}

#endif // GK_DEVICE_DIRECTX9
